<template>
  <div>
    <!-- 整体布局 -->
    <div class="box">
      <van-pull-refresh v-model="myrefreshing" @refresh="onRefresh">
        <van-list v-model="myloading" :finished="myfinished" @load="onLoad">
          <van-cell v-for="item in myshoplist" :key="item.id" @click="mygodeilt(item.id)">
            <div>
              <van-image width="100%" height="100%" lazy-load :src="item.img_url"/>
              <p class="shoptitle">{{item.title}}</p>
              <div class="allsell">
                <p class="btop">
                  <span class="newsell">￥{{item.sell_price}}</span>
                  <span class="oldsell">￥{{item.market_price}}</span>
                </p>
                <p class="btt clearfix">
                  <span class="tl">热卖中</span>
                  <span class="tr">剩{{item.stock_quantity}}件</span>
                </p>
              </div>
            </div>
          </van-cell>
          <template slot="finished">
            <span>没有更多了,真的没有了</span>
          </template>
        </van-list>
      </van-pull-refresh>
    </div>
  </div>
</template>
           
<script>
import { shopget } from "@/api";
export default {
  data() {
    return {
      mypage: 1,
      myshoplist: [],
      myloading: false,
      myfinished: false,
      myrefreshing: false
    };
  },
  methods: {
    async getsgoplist() {
      var res = await shopget(this.mypage);
      this.myshoplist.push(...res.data.message);
    },
    onLoad() {
      setTimeout(() => {
        if (this.refreshing) {
          this.myshoplist = [];
          this.mypage = 1;
          this.getsgoplist();
          this.myrefreshing = false;
        } else {
          this.mypage++;
          this.getsgoplist();
          this.myloading = false;
          if (this.myshoplist.length >= 15) {
            this.myfinished = true;
          }
          this.myrefreshing = false;
        }
      }, 1000);
    },
    onRefresh() {
      // 清空列表数据
      this.myfinished = false;
      // 重新加载数据
      this.myloading = true;
      this.onLoad();
    },
    mygodeilt(id) {
      this.$router.push({ path: `/details/${id}` });
    }
  },

  created() {
    this.getsgoplist();
  }
};
</script>
<style scoped lang=less>
.van-list {
  justify-content: space-around;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  margin: 5px 10px 50px 10px;
  .van-cell {
    width: 48%;
    border: 1px solid #ccc;
    margin: 10px 0;
    padding: 0;
    align-content: space-between;
    position: relative;
    display: flex;
    box-sizing: border-box;
    overflow: hidden;
    color: #323233;
    font-size: 14px;
    line-height: 24px;
    background-color: #fff;
    .van-image {
      text-align: center;
      padding: 10px;
      min-height: 180px;
      position: relative;
      display: inline-block;
    }
    .shoptitle {
      font-size: 14px;
      color: #000;
      text-align: left;
      overflow: hidden;
      text-overflow: ellipsis;
      padding: 4px 10px;
      height: 49px;
    }
    .allsell {
      width: 100%;
      background: #eee;
      padding: 5px 0;
      .btop {
        text-align: left;
        padding: 0 10px;
        .newsell {
          font-size: 16px;
          color: red;
          margin-right: 15px;
        }
        .oldsell {
          text-decoration: line-through;
        }
      }
      .btt {
        padding: 0 10px;
        tl {
          float: left;
        }
        .tr {
          float: right;
        }
      }
    }
  }
  .van-list__finished-text {
    width: 100% !important;
  }
}
</style>